package com.est.dase.database;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;
/**
*
* @author Fernando Geraldes, Jaime Santos, Jorge Silva
*
*/
public class CreateDataBaseDevice {

	private DataBase dataBase;
	private SQLiteDatabase db;
	private final Context context;
	private SQLiteStatement sQLiteStatement;

	/**
	 * Constructor - takes the context to allow the database to be
	 * opened/created
	 */
	public CreateDataBaseDevice(Context ctx) {
		this.context = ctx;

		this.dataBase = new DataBase(context);
		db = dataBase.getReadableDatabase();
		db = dataBase.getWritableDatabase();
		dataBase.getWritableDatabase();

	}

	public long insert(String name, int index) {
		this.sQLiteStatement.bindString(index, name);
		return this.sQLiteStatement.executeInsert();
	}

	public void drop(){
		dataBase.onUpgrade(db, 1, 2);
	}

	public void close() {
		if(db.isOpen())
			dataBase.close();
	}

	public DataBase getDataBase() {
		return dataBase;
	}

	public void open(){
		try {
			dataBase.openDataBase();
		}catch(SQLException sqle){

			throw sqle;

		}
	}

}
